<template>
  <div class="_wz_cent_main _wz_staff">
    <Card :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="80" inline>
        <FormItem label="登录账号">
          <i-input v-model="formDataSearch.userName" placeholder="请填写登录账号" clearable />
        </FormItem>
        <FormItem label="用户名">
          <i-input v-model="formDataSearch.name" placeholder="请填写用户名" clearable />
        </FormItem>
        <FormItem label="归属部门" v-if="searchType">
          <i-input v-model="formDataSearch.inOrgName" placeholder="请填写归属部门" clearable />
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>

    <Card :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="addTableData">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
    <Drawer :title="formTitle" v-model="formOperation" width="720" :draggable="true" :mask-closable="false" :styles="formOperationStyles">
      <staffAdd v-if="formOperation" :selectData="selectData"  @closeFun="closeFun"></staffAdd>
    </Drawer>
  </div>
</template>
<script>


import wzTbale from "../../components/table/table";
import staffAdd from "./staffAdd.vue";
export default {
  components: {
    wzTbale,//列表
    staffAdd,//系统用户添加
  },
  data () {
    return {
      selectData:{},
      subDeptList: [],//运输企业
      searchType:false,//搜索条件
      tableData: {
        url: this.apiUrl.systemUserSystemUserPageList,//请求地址
        method: 'post',//请求方式
        where: {},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 80, align: 'center', title: '序号'},
          { title: '登录账号', minWidth: 120, key: 'username'},
          { title: '用户名', minWidth: 120, key: 'name'},
          { title: '归属机构', minWidth: 260, key: 'deptName'},
          { title: '联系电话', minWidth: 120, key: 'mobile'},
          { title: '电子邮箱', minWidth: 140, key: 'email'},
          { title: '归属部门', minWidth: 140, key: 'inOrgName'},
          { title: '负责人状态', minWidth: 120, key: 'inOrgState',
            render: (h, params) => {
              return h('span', {}, !!params.row.inOrgState?'主管':'--')
            }
          },
          { title: '岗位职务', minWidth: 120, key: 'inDutyName'},
          {
            title: '创建时间', minWidth: 180, key: 'createTime',
            render: (h, params) => {
              return h('span', {}, this.public.timeFormatting(params.row.createTime, "yyyy-MM-dd hh:mm:ss"))
            }
          },
          {title: '登陆时间', minWidth: 180, key: 'loginTime',},
          {
            title: '使用状态', fixed: 'right', minWidth: 120, key: 'status',
            render: (h, params) => {
              return h('Tag', {
                props: {
                  type: 'dot',
                  color: (params.row.status == 1) ? "success" : "error"
                }
              }, (params.row.status == 1) ? "正常" : "禁用")
            }
          },
          {title: '操作', fixed: 'right', width: 180,
            render: (h, params) => {
              let operationButtons = [];
              //修改
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.formTitle = "修改"
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.formOperation = true;
                    }
                  }
                }, '修改')
              );

              //删除
              operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      var that = this
                      that.$Modal.confirm({
                        title: '删除提醒',
                        content: '确定要删除选中的记录？',
                        onOk: () => {
                          if(params.row.id == 1 || params.row.state == 1){
                            that.$Message.error('管理员禁止删除');
                            return;
                          }
                          that.axios.post(that.apiUrl.systemUserSystemUserDelete, { uuid: params.row.uuid }).then(res => {
                            if (!!res) {
                              that.$Message.success('数据删除成功.')
                              that.$refs.wzTbale.tableLoadData()
                            }
                          }).catch(err => {
                            console.log("失败", err)
                          })
                        },
                        onCancel: () => {
                          //点击取消
                        }
                      })
                    }
                  }
                }, "删除")
              );

              operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      var that = this
                      that.$Modal.confirm({
                        title: '重置提醒',
                        content: '确定要重置选中的用户密码？',
                        onOk: () => {
                          that.$Spin.show()
                          that.axios.post(that.apiUrl.systemUserSystemUserResetPass, { uuid: params.row.uuid }).then(res => {
                            that.$Spin.hide()
                            if (!!res) {
                              that.$Message.success('密码重置成功')
                              that.$refs.wzTbale.tableLoadData()
                            }
                          }).catch(err => {
                            console.log("失败", err)
                          })
                        },
                        onCancel: () => {
                          //点击取消
                        }
                      })

                    }
                  }
                }, "重置密码")
              );

              return h('div', operationButtons);
            }
          },
        ],
        format: {//返回数据格式
          list: [ 'data'],//数据list
          count: [ 'count'],//数据总量
        },
      },
      formDataSearch: {},//搜索表单数据
      formOperation: false,//表单左侧移出
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      formTitle: "",//表单名称
    }
  },
  beforeCreate () {//beforeCreate创建前状态


  },
  created () {//created创建完毕状态

  },
  beforeMount () {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程


  },
  mounted () {//mounted 挂载结束状态
    var that = this
    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })
  },
  methods: {//执行的方法
    addTableData () {//table添加
      var that = this
      that.formTitle = "添加"
      that.selectData = { status: 0,inOrgState:0}
      that.formOperation = true
    },
    searchSubmit () {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true)
    },
    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$refs.wzTbale.tableLoadData();
      }
      that.formOperation = false;
    },
  },
  watch: {//监听

  },
  props: {//接收来自父组件的数据

  },
  beforeUpdate () {//beforeUpdate 更新前状态

  },
  updated () {//updated 更新完成状态

  },
  beforeDestroy () {//beforeDestroy 销毁前状态

  },
  destroyed () {//destroyed 销毁完成状态

  }
}
</script>

<style lang="less">
._wz_staff {
  //不固定头部  列表到底
  display: flex;
  flex-direction: column;
}
</style>

